import rclpy
from rclpy.node import Node


class PersonNode(Node):
    def __init__(self,node_name, name, age):
        super().__init__(node_name)
        self.name = name
        self.age = age
        print("PersonNode init方法被调用")

    def eat(self,food_name : str):
        print(f'我是{self.name},我已经{self.age}岁了，我在吃{food_name}')
        self.get_logger().info(f'我是{self.name},我已经{self.age}岁了，我在吃{food_name}')


def main(args=None):
    rclpy.init(args=args)
    node = PersonNode('zhangsan','张三', 18)
    node.eat('苹果')
    rclpy.spin(node)
    rclpy.shutdown()


if __name__ == '__main__':
    person = PersonNode('zhagsan','张三', 18)
    person.eat('苹果')
